<%-- 
    Document   : transaction
    Created on : Dec 6, 2011, 8:00:39 PM
    Author     : Michael
--%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<% if(session.getAttribute("Access").equals("Customer"))
    response.sendRedirect("gohome.jsp");
%>
<%@page import="java.sql.*;"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
         Connection conn=null;
        try
        {
             conn = new DBClasses.GetConnection().getConnection();
             ResultSet rs = conn.createStatement().executeQuery("SELECT AccountNo, Concat(AccountNo, ': ', Email) AS Name FROM customer ORDER BY Email");           
             ResultSet rs1 = conn.createStatement().executeQuery("SELECT AdvertisementID, Concat(AdvertisementID, ': ', ItemName) AS Item FROM advertisement ORDER BY ItemName");
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Record Transaction</title>
</head>
<body>
<table width="800" border="0">
  <tr>
    <td><input type="button" value="Home" onclick="window.location='gohome.jsp'"/>&nbsp;
          <input type="button" value="Log Out" onclick="window.location='logout.jsp'"/></td>
  </tr>
    <tr><td align="left"><h2>Record Transaction</h2></td></tr>
    <tr>
    <td align="left">
        <form style="padding-right: 200px;" name="sale" action="purchase.jsp" method="post"> 
            <label>Account: </label>
            <select name="accountno">
                <% while(rs.next()) { %>
                <option value="<%=rs.getInt("AccountNo")%>"><%=rs.getString("Name")%></option>
                <% } %>
            </select>
            <br />
            
            <label>Item: </label>
            <select name="itemid">
                <% while(rs1.next()) { %>
                <option value="<%=rs1.getInt("AdvertisementID")%>"><%=rs1.getString("Item")%></option>
                <% } %>
            </select>
            <br />
            
            <label>Number of Units: </label>
            <input type="text" maxlength="50" name="itemamount" /><br />    
        </form>
    </td>
    </tr>
  <tr>
    <td align="right" style="padding-right: 200px;"><input type="button" value="Create" onclick="document.sale.submit()"/>&nbsp;
    <input type="button" value="Cancel" onclick="window.location='gohome.jsp'"/></td>
  </tr>
</table>
       <% }
        catch(Exception e) { e.printStackTrace(); response.sendRedirect("gohome.jsp"); }

        finally
        {
            try{ conn.close(); }
            catch(Exception e) { response.sendRedirect("gohome.jsp"); }
        }   
    %>
</body>
</html>
